﻿Module mdl_QueryService

#Region " QueryService"
        Private Const ClientNo As String = "900002"
#End Region



#Region "QueryServiceExecute"
    '●着工入力のチェック
    Public Function QueryServiceExecute(ByVal OBJInParam As InSiteWebService.InQuery) As InSiteWebService.OutQuery

        Dim Txn As New InSiteWebService.InSiteServiceSoapClient
        Dim OBJOutParam As New InSiteWebService.OutQuery

        '●変数の初期化
        OBJInParam.header = New InSiteWebService.InHeader
        OBJInParam.header.User = INSITE_USER
        OBJInParam.header.Password = PASSWORD

        Try

            OBJOutParam = Txn.QueryService_Execute(OBJInParam)

            Return OBJOutParam

        Catch ex As Exception

            OBJOutParam.header = New InSiteWebService.OutHeader
            OBJOutParam.header.Status = STS_ERROR
            OBJOutParam.header.ResultMessage = New String() {ex.Message & " (" & ex.InnerException.Message & ")"}
            OBJOutParam.header.ResultCode = New String() {"99999"}

            Return OBJOutParam

        Finally
            Txn = Nothing
            OBJOutParam = Nothing
        End Try

    End Function
#End Region

#Region "QueryServiceExecutePro"
    ''●着工入力のチェック
    'Public Function QueryServiceExecute(ByVal OBJInParam As InSiteWebServicePro.InQuery) As InSiteWebServicePro.OutQuery

    '    Dim Txn As New InSiteWebServicePro.InSiteServiceSoapClient
    '    Dim OBJOutParam As New InSiteWebServicePro.OutQuery

    '    '●変数の初期化
    '    OBJInParam.header = New InSiteWebServicePro.InHeader
    '    OBJInParam.header.User = INSITE_USER
    '    OBJInParam.header.Password = PASSWORD

    '    Try

    '        OBJOutParam = Txn.QueryService_Execute(OBJInParam)

    '        Return OBJOutParam

    '    Catch ex As Exception

    '        OBJOutParam.header.Status = STS_ERROR
    '        OBJOutParam.header.ResultMessage(0) = ex.Message & " (" & ex.InnerException.Message & ")"

    '        Return OBJOutParam

    '    Finally
    '        Txn = Nothing
    '        OBJOutParam = Nothing
    '    End Try

    'End Function
#End Region

#Region "QueryServiceExecute"
    '●着工入力のチェック
    Public Function LimitTimeServiceExecute(ByVal OBJInParam As InSiteWebService.InLimitTimeControl) As InSiteWebService.OutLimitTimeControl()

        Dim Txn As New InSiteWebService.InSiteServiceSoapClient
        Dim OBJOutParam(1) As InSiteWebService.OutLimitTimeControl

        '●変数の初期化
        OBJInParam.Header = New InSiteWebService.InHeader
        OBJInParam.Header.User = INSITE_USER
        OBJInParam.Header.Password = PASSWORD

        Try

            OBJOutParam = Txn.LimitTimeControlGetLimitTime(OBJInParam)

            Return OBJOutParam

        Catch ex As Exception
            OBJOutParam(0).Header.Status = STS_ERROR
            OBJOutParam(0).Header.ResultMessage(0) = ex.Message & " (" & ex.InnerException.Message & ")"

            Return OBJOutParam

        Finally
            Txn = Nothing
            OBJOutParam = Nothing
        End Try

    End Function
#End Region
#Region "QueryServiceExecute"
    '●着工入力のチェック
    Public Function ViewLotServiceExecute(ByVal OBJInParam As InSiteWebService.InViewLot) As InSiteWebService.OutLotWaferInf

        Dim Txn As New InSiteWebService.InSiteServiceSoapClient
        Dim OBJOutParam As InSiteWebService.OutLotWaferInf = New InSiteWebService.OutLotWaferInf

        '●変数の初期化
        OBJInParam.Header = New InSiteWebService.InHeader
        OBJInParam.Header.User = INSITE_USER
        OBJInParam.Header.Password = PASSWORD

        Try

            OBJOutParam = Txn.ViewLotService_GetWaferInf(OBJInParam)

            Return OBJOutParam

        Catch ex As Exception
            OBJOutParam.Header.Status = STS_ERROR
            OBJOutParam.Header.ResultMessage(0) = ex.Message & " (" & ex.InnerException.Message & ")"

            Return OBJOutParam

        Finally
            Txn = Nothing
            OBJOutParam = Nothing
        End Try

    End Function
#End Region
#Region "GetLimitTime"
    '●着工不可になる最少時間を取得する
    Public Function GetLimitTime(ByVal LotID As String, ByVal FromProcCode As String, ByVal ToProcCode As String) As Integer

        'テスト用
        Return 48

        Dim OBJInParam As InSiteWebService.InLimitTimeControl = New InSiteWebService.InLimitTimeControl
        OBJInParam.Lot = LotID
        OBJInParam.Operation = FromProcCode
        OBJInParam.ToOperation = ToProcCode

        Dim bsite_LimitTime() As InSiteWebService.OutLimitTimeControl = LimitTimeServiceExecute(OBJInParam)

        Dim i As Integer
        Dim MinLimitTime As Integer
        For i = 0 To bsite_LimitTime.Length - 2
            If i = 0 Then
                MinLimitTime = System.Math.Min(CInt(bsite_LimitTime(i).MinLimitTimeE), CInt(bsite_LimitTime(i + 1).MinLimitTimeE))
            Else
                MinLimitTime = System.Math.Min(MinLimitTime, CInt(bsite_LimitTime(i + 1).MinLimitTimeE))
            End If
        Next
        Return MinLimitTime
    End Function
#End Region
#Region "GetWaferInf"
    '●着工不可になる最少時間を取得する
    Public Function GetWaferInf(ByVal LotID As String, ByVal FromProcCode As String, ByVal ToProcCode As String) As Integer

        'テスト用
        Return 24

        Dim OBJInParam As InSiteWebService.InViewLot = New InSiteWebService.InViewLot
        OBJInParam.Name = LotID

        Dim bsite_wafer As InSiteWebService.OutLotWaferInf = ViewLotServiceExecute(OBJInParam)

        Return bsite_wafer.WaferInf.Count

    End Function
#End Region
End Module
